<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>公告编辑|新增</title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp" %> 
  <style type="text/css">
    	div.box-body {
    		margin-top:7px;
    	}
    </style>
  
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>公告<%= "2".equals(request.getParameter("opType"))? "新增" : "编辑" %></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">招标采购管理</a></li>
            <li class="active"><a href="#">公告编辑</a></li>
        </ol>
    </section>
    <section class="content">
      <form id="submitForm" role="form" class="form-horizontal" action="${ctx}/sysNotice/toSaveOrEditeSysNotice.html">
    	<div class=" box box-success">
    		      <div class="box-body">
                 	<div class="form-group form-group-xs">
                        <label for="exampleInputEmail1" class="col-sm-2 text-right">公告标题：</label>
                        <div class="col-sm-9 text-left">
                            <input class="form-control" name="title" id="title" placeholder="公告名称" type="text" onblur="validateName()">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="exampleInputEmail1" class="col-sm-2 text-right">所属项目：</label>
                        <div class="col-sm-9 text-left">
                            <select class='form-control' id="projectId" name="projectId">
								<option value="">请选择</option>
								<c:forEach items="${projectList}" var="item">
									<option value="${item.projId }" ${projId == item.projId ? "selected='selected'" : ""}>${item.name}</option>
								</c:forEach>
							</select>
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="exampleInputEmail1" class="col-sm-2 text-right">发布机构：</label>
                        <div class="col-sm-9 text-left">
                            <input class="form-control" name="org" id="org" placeholder="发布机构" type="text">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="exampleInputEmail1" class="col-sm-2 text-right">URL地址：</label>
                        <div class="col-sm-9 text-left">
                            <input class="form-control" name="url" id="url" placeholder="url地址" type="text">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="exampleInputEmail1" class="col-sm-2 text-right">发布时间：</label>
                        <div class="col-sm-9 text-left">
                            <input class="form-control" name="dateTime" id="dateTime" placeholder="发布时间" type="text" data-provide="datepicker" data-date-fmt="yyyy-MM-dd HH:mm:ss">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="inputTextAlter4" class="col-sm-2 text-right">公告内容：</label>
                        <div class="col-sm-9 text-left">
                            <div id="editor" style="height:300px;" name="content">
                            </div>
                        </div>
                    </div>
                    <input type="hidden" value="${sysNotice.sysNoticeId }" id="sysNoticId" name="sysNoticeId">
                    <!-- 保存项目公告id -->
                    <input type="hidden" value="${bidProjSysNotice.projSysNoticeId }" id="projSysNoticeId" name="projSysNoticeId">
                </div>
                <div class="box-footer text-center">
                    <a onclick ="save()" class="btn btn-success btn-sm">保&nbsp;存</a>
                    <a href="toSysNoticeList.html?projId=${projId }" class="btn btn-danger btn-sm">返&nbsp;回</a>
                </div>
        	</div>
        </form>
    </section>
     <%@ include file="/WEB-INF/component/commonJS.jsp" %>  
     <script src="${ctx}/lib/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript">
        var ue;
        function save(){
        	if(!validate()){
        		return;
        	}
    		$.HN.message.confirm('确定要保存吗？', '', '').on(function (e) {
                   if (e) {
    			$("#submitForm").ajaxSubmit({
    				 type: 'post',
    				dataType : "json",
    				timeout: 10000,
    				success : function(result, statusText) {
    					if (result.success) {
    						$.HN.message.alert("保存成功！", "消息", "success", function() {
    							window.location.href="${ctx}/sysNotice/toSysNoticeList.html?projId=${projId }";
    						});
    					} else {
    						$.HN.message.alert(result.msg || "", "消息", "error");
    					}
    				}
    			});
             }
           });
        }
        function validateName(){
        	var title = $("#title").val();//获取公告标题
        	var hospCode = $.trim($("#hospCode").val());
			$.post("${ctx}/sysNotice/valitdateTitle.html", {
				title:title,
			}, function(result) {
				if (result=="false") {
					top.$.alert('公告标题已存在，请重新填写！',  'warn');
					 $("#title").val("");
				} 
			}, "json") 
        }
        function validate(){
        	var title = $.trim($("#title").val());
    		if (title == null || title == "") {
    			$.HN.message.alert("公告标题不能为空！", "消息", "warn");
    			return false;
    		} 

    		var org = $.trim($("#org").val());
    		if (org == null || org == "") {
    			$.HN.message.alert("请输入发布机构！", "消息", "warn");
    			return false;
    		}

    		var dateTime = $.trim($("#dateTime").val());
    		if (dateTime == null || dateTime == "") {
    			$.HN.message.alert("发布时间不能为空！", "消息", "warn");
    			return false;
    		}
    		return true;
        }
        
        function back(){
        	window.location.href="toSysNoticeList.html?projId=${projId }"
        }
		$(function() {
		    ue = UE.getEditor('editor');
		    var opType = "${opType}";
			ue.ready(function() {
				if(opType=="1"){
					$("#title").val("${sysNotice.title}");
		        	$("#url").val("${sysNotice.url}");
		        	$("#org").val("${sysNotice.org}");
		        	$("#dateTime").val("${dateTime}");
		        	var content="${sysNotice.content}";
		        	ue.setContent("${sysNotice.content}");
				}
			  
			});
			$("#projectId").val("${projId}");
		}
		);
    </script>
</body>
</html>
